package com.example.reward.api;

import com.example.reward.intercept.SecureInterceptor;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {
    private static final String BASE_URL = "https://reward.xiaoyihao.tech/api/";
//    private static final String BASE_URL = "http://192.168.1.4:86/";
    private static Retrofit retrofit;

    public static Retrofit getClient() {
        if (retrofit == null) {
            // 创建拦截器
            SecureInterceptor secureInterceptor = new SecureInterceptor("app-client", "jPwhOLr5Xa4zjOZS1DzaumIm9IiSC7pQ5bIZERwgLco=");

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);

            OkHttpClient client = new OkHttpClient.Builder()
                    .addInterceptor(secureInterceptor)
                    .addInterceptor(logging) // 加入日志拦截器
                    .build();

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }
}
